<!--
 * @Author: 1960116313@qq.com 1960116313@qq.com
 * @Date: 2023-10-16 14:58:49
 * @LastEditors: 1960116313@qq.com 1960116313@qq.com
 * @LastEditTime: 2023-10-24 16:01:27
 * @FilePath: \青鸟翼联ai小程序\src\pages\login\components\login-wx\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <view class="login-content">
    <view class="other">
      <button
        v-if="props.Check"
        class="phone"
        plain
        open-type="getPhoneNumber"
        @getphonenumber="getPhoneNumber"
      >
        <view>其他登录方式</view>
        <!-- <img
          src="@/static/images/bg/wx.png"
          style="width: 80rpx; height: 80rpx"
        /> -->
      </button>
      <button v-else class="phone" plain @click="handleLoginWx">
        <view>其他登录方式</view>
        <!-- <img
          src="@/static/images/bg/wx.png"
          style="width: 80rpx; height: 80rpx"
        /> -->
      </button>
    </view>
  </view>
</template>

<script lang="ts" setup>
import { ref, reactive, shallowRef } from "vue";
import { onReady, onShow } from "@dcloudio/uni-app";
// import { useUserStore } from "@/stores/user/user";
// import { GrantType } from "@/enums/loginTypeEnums";
// const userStore = useUserStore();
const code = ref("");
const props = defineProps(["Check", "modalShow"]);
const emit = defineEmits(["change:check"]);

const getCode = () => {
  uni.getProvider({
    service: "oauth",
    success: function (res: any) {
      uni.login({
        provider: res.provider,
        success: function (loginRes) {
          code.value = loginRes.code;
        },
      });
    },
  });
};
getCode();
const getPhoneNumber = async (e: any) => {
  if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
    //用户点击拒绝
    console.log("用户点击拒绝");
  } else {
    //允许授权
    uni.showLoading({
      title: "正在登录中...",
    });
    const params = {
      codeOpenId: code.value,
      codePhone: e.detail.code,
      type: "wechatOpenId",
      // grant_type: GrantType.WX,
    };
    // await userStore.login(params);
    uni.hideLoading();
    uni.$u.toast("登录成功");
    uni.reLaunch({
      url: "/pages/index/index",
    });
  }
};

//勾选安全协议
const handleLoginWx = () => {
  // uni.$u.toast("请勾选《用户协议》");
};
</script>

<style lang="scss" scoped>
.other {
  width: 100%;
  padding-top: 100rpx;

  display: flex;
  flex-direction: column;
  align-items: center;
}

.phone {
  position: absolute;
  border: none;
  font-size: 28rpx;
  font-family: PingFang SC;
  font-weight: 400;
  text-align: center;
}
</style>
